<%
String status = "";
if(request.getSession().getAttribute("status") != null){
	status = (String)request.getSession().getAttribute("status");
}else if(!status.equals("ingelogd")){
	response.sendRedirect("index.jsp?message=Log+eerst+in+om+verder+te+gaan");
}
//session.removeAttribute("status");
%>
<%@page import="java.sql.*"%>
<%@page import="model.*"%>
<%@page import="domein.*"%>
<%@ page import = "java.util.Date,java.text.SimpleDateFormat,java.text.ParseException"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title>Incentro Event Inviting System</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="style.css" />
<link rel="shortcut icon" type="image/x-icon" href="/img/favicon.ico" />
</head>

<body>

	<div id="wrapper">

		<div id="header">
			<a href="#" id="logo"><img src="img/logo.png" /></a>
		</div>

		<h3>
			Archief
			<%
			//out.print(request.getSession().getAttribute("userMail"));
			//request.getSession().removeAttribute("userMail");
			//String message = request.getParameter("message");
		//%>
		</h3>

		<div id="search-form">
		
		<a href="eOverzicht.jsp"><input type="submit" value="Evenementen" class="terugButton" style="width:100px;"/></a>
		
		<a href="event/evenementMaken.jsp"><input type="submit" value="Event toevoegen" class="terugButton" style="width:150px;"/></a>


		<a href="voegGebruikerToe.jsp"><input type="submit" value="Gebruiker toevoegen" class="terugButton" style="width:150px;"/></a>
		
		<a href="logUit.jsp"><input type="submit" value="Log uit" class="terugButton" style="width:80px;"/></a>
		
			<form method="post" action="Archief.jsp">
				<input type="submit" value="Search" />
				<input type="text" id="searchField" name="id" placeholder="Search"></input>
			</form>

		</div>

		<table class="table" summary="Evenementen overzicht">
			<thead>
				<tr>
					<th scope="col">Evenement</th>
					<th scope="col">Contactpersoon</th>
					<th scope="col" id="datumCol">Datum</th>
					<th scope="col">Details</th>
					<th scope="col">Status</th>
				</tr>
			</thead>
			<tbody>
				<%
					if (request.getParameter("id") != null) {

						String value = request.getParameter("id");
						EvenementenIO seIo = new EvenementenIO();
						int counter = 1;
						for (Evenement e : seIo.SearchListEvenementen(value)) {
							String datum = e.getDatum();
							Date datumpje = new SimpleDateFormat("yyyy-MM-dd").parse(datum);
							//System.out.println(datumpje); // Sat Jan 02 00:00:00 BOT 2010
							
							Date huidigeDatum = new Date();
							//System.out.println(huidigeDatum);
							
							if(datumpje.compareTo(huidigeDatum)<0){
							
							if (counter == 1) {
				%><tr class="odd">
					<%
						counter = 2;
								} else {
					%>
					<tr>
						<%
							counter = 1;
									}
						%>

						<td>
							<%
								out.print(e.getNaam());
							%>
						</td>
						<td>
							<%
								out.print(e.getContactPersoon());
							%>
						</td>
						<td>
							<%
								String date = e.getDatum();
								String dateYear = date.substring(0,4);
								String dateMonth = date.substring(5,7);
								String dateDay = date.substring(8,10);
								out.print(dateDay + "-" + dateMonth + "-" + dateYear);
							%>
						</td>
						<td><a
							href="eDetails.jsp?eventID=<%out.print(e.getEventID());%>">Details</a></td>
						<td><a href="status.jsp?eventID=<%out.print(e.getEventID());%>">Status</a></td>
					</tr>
					<% 
						}
					%> 
 					<% 
						}
					%> 
 
			
		</table>
		<%
			} else {
				EvenementenIO eIo = new EvenementenIO();
				int counter = 1;
				for (Evenement e : eIo.listEvenementen()) {
					
					
					String datum = e.getDatum();
					Date datumpje = new SimpleDateFormat("yyyy-MM-dd").parse(datum);
					//System.out.println(datumpje); // Sat Jan 02 00:00:00 BOT 2010
					
					Date huidigeDatum = new Date();
					//System.out.println(huidigeDatum);
					
					if(datumpje.compareTo(huidigeDatum)<0){
					
					
					
					
					
					
					if (counter == 1) {
		%><tr class="odd">
			<%
				counter = 2;
						} else {
			%>
			<tr>
				<%
					counter = 1;
							}
				%>

				<td>
					<%
						out.print(e.getNaam());
					%>
				</td>
				<td>
					<%
						out.print(e.getContactPersoon());
					%>
				</td>
				<td>
					<%
						String date = e.getDatum();
						String dateYear = date.substring(0,4);
						String dateMonth = date.substring(5,7);
						String dateDay = date.substring(8,10);
						out.print(dateDay + "-" + dateMonth + "-" + dateYear);
						
						
						
		
						
						
						
					%>
				</td>
				<td><a href="eDetails.jsp?eventID=<%out.print(e.getEventID());%>">Details</a></td>
				<td><a href="ArchiefStatus.jsp?eventID=<%out.print(e.getEventID());%>">Status</a></td>
			</tr>
			<%
				} 
			%>
			<%
				}
			%>
			<%
				}
			%>
		
		</tbody>
		</table>


	</div>

</body>

</html>